$(function () {

    $.get(config.baseUrl+"/areaDict/queryListByParentid.json",{parentid: 0}, function (result) {
        if (result.status == 200) {
            var html = '<option value="">---请选择省---</option>';
            html += template("optionScript1", result);
            $("#sheng").html(html)
        }
    }, "json");
    $("#sheng").change(function (e) {
        e.preventDefault();
        var shengId = $(this).val();
        $.get(config.baseUrl+"/areaDict/queryListByParentid.json",{parentid: shengId}, function (result) {
            if (result.status == 200) {
                var html = '<option value="">---请选择市---</option>';
                html += template("optionScript1", result);
                $("#shi").html(html);
                $("#areaId").change();
            }
        }, "json");

    });

    $("#shi").change(function (e) {
        e.preventDefault();
        var shi = $(this).val();
        $.get(config.baseUrl+"/areaDict/queryListByParentid.json",{parentid: shi}, function (result) {
            if (result.status == 200) {
                var html = '<option value="">---请选择区---</option>';
                html += template("optionScript1", result);
                $("#areaId").html(html);
            }
        }, "json");
    });

    /*
       * 删除地址
       * */
    function deleteAddress(addressId) {
        $.ajax({
            type: "get",
            url: url + "address/deleteAddress.json",
            data: {"addressId": addressId},
            dataType: "json",
            success: function (data) {

            }
        })
    }

    /*
       * 设置为默认地址
       * */
    function updatDefalutAddress(addressId) {
        var param = {
            userId: userId,
            id: addressId,
            defaultAddress: "1"
        }
        $.ajax({
            type: "post",
            url: config.baseUrl + "address/updateDefaultAddress.json",
            data: param,
            dataType: "json",
            success: function (data) {

            }
        })
    }

    /*
       * 地址详情
       * */
    function getAddress(addressId) {
        $.ajax({
            type: "get",
            url: config.baseUrl + "address/getAddress.json?addressId=" + addressId,
            dataType: "json",
            success: function (data) {
                var tempData = template('', data);
                $("#").html(tempData);
            }
        })
    }


})

/*
       * 添加地址
       * */
function saveAddress() {
    var param = {
        name: $("#name").val(),
        phone: $("#phone").val(),
        areaId: $("#areaId").val(),
        detailAddress: $("#detailAddress").val()
        // defaultAddress: $("#defaultAddress").val()
    }
    $.ajax({
        type: "post",
        url: config.baseUrl + "address/saveAddress.json",
        data: param,
        dataType: "json",
        success: function (data) {

        }
    })
    return false;
};